package com.chinamoney.wppm.listener;

import java.util.Arrays;

import org.activiti.engine.delegate.DelegateTask;
import org.activiti.engine.delegate.TaskListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.chinamoney.wppm.util.ProcessPointDefinitionUtil;

/**
 * 设置流程审批人
 * @author JZH
 *
 */
public class EformApproverListener implements TaskListener {
	
	private Logger logger = LoggerFactory.getLogger(EformApproverListener.class);

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
	public void notify(DelegateTask delegateTask) {
		String taskName = delegateTask.getName();
		logger.debug("【流程审批人监听器】任务名称："+taskName);
		if("需求提出".equals(taskName)) {//之后可以将创建表单的人传进来
			delegateTask.setAssignee("Jason_Jiang");
		} else {
			String type = ProcessPointDefinitionUtil.getNodeType("电子需求单", taskName);
			String processInstanceId = delegateTask.getProcessInstanceId();
			String approver =  delegateTask.getVariable(processInstanceId+":"+taskName).toString();
			if(ProcessPointDefinitionUtil.NODE_TYPE_SINGLE_APPROVER.equals(type)) { //单人审批
				delegateTask.setAssignee(approver);
			} else if(ProcessPointDefinitionUtil.NODE_TYPE_MULTIPLE_APPROVER.equals(type)) { //多人审批
				delegateTask.addCandidateUsers(Arrays.asList(approver.split(";")));
			}
		}
	}

}
